﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using SSAT.Utils.Freezer;
using System.Drawing;

namespace SSAT.Commands
{
    /// <summary>
    /// Represents design pattern under the alias Command. 
    /// </summary>
    internal abstract class CommandBase
    {
        private ControlFreezer _dependentControls = new ControlFreezer();

        /// <summary>
        /// This name will be displayed in the menu (context) strip item. If
        /// this property returns null or empty string then item won't change 
        /// it's text.
        /// </summary>
        public virtual string DisplayName
        {
            get { return string.Empty; }
        }

        public bool Enabled
        {
            get { return !DependentControls.IsFreezed; }
            set
            {
                if (value)
                {
                    DependentControls.Unfreeze();
                }
                else
                {
                    DependentControls.Freeze();
                }
            }
        }

        private ControlFreezer DependentControls
        {
            get { return _dependentControls ?? new ControlFreezer(); }
            set { _dependentControls = value; }
        }

        public abstract void Execute();

        public void AddDependentControl(ToolStripItem item)
        {
            DependentControls.AddControl(item);
        }
    }
}
